package com.example.exception.controller;

import com.example.exception.constant.HttpStatus;
import com.example.exception.domain.AjaxResult;
import com.example.exception.domain.User;
import com.example.exception.exception.ServiceException;
import com.example.exception.mapper.UserMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.net.BindException;
import java.nio.file.AccessDeniedException;

/**
 * @author HTT
 */
@RestController
@RequestMapping("/user")
public class UserController {

    /**
     * 权限测试
     */
    @GetMapping("/auth")
    public void auth() throws AccessDeniedException {
        throw new AccessDeniedException("暂无权限");
    }
    /**
     * 参数验证异常测试
     * @param user
     */
    @PostMapping("/valid")
    public void Valid(@Valid @RequestBody User user){
        System.out.println(user.toString());
    }

    /**
     * 请求不支持异常测试
     */
    @PostMapping("/request")
    public void request() {
        System.out.println("request");
    }

    /**
     * 运行异常
     */
    @GetMapping("/runtimeException")
    public void runtimeException(){
        throw new RuntimeException();
    }

    /**
     * 业务自定义异常
     */
    @GetMapping("/serviceException")
    public void serviceException() {
        throw new ServiceException("业务异常！");
    }

    /**
     * 全局异常
     */
    @GetMapping("/exception")
    public void exception() throws Exception {
        throw new Exception("全局异常！");
    }

    @Resource
    private UserMapper userMapper;
    /**
     * 数据库异常
     */
    @GetMapping("/badSqlGrammarException")
    public void badSqlGrammarException() throws Exception {
        userMapper.select();
    }



}
